package com.company.oa.document.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.company.oa.common.api.Result;
import com.company.oa.document.dto.ApprovalDTO;
import com.company.oa.document.entity.ApprovalRecord;
import com.company.oa.document.service.ApprovalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 审批控制器
 */
@RestController
@RequestMapping("/approvals")
public class ApprovalController {

    @Autowired
    private ApprovalService approvalService;

    /**
     * 审批公文
     */
    @PostMapping
    public Result<Boolean> approveDocument(
            @RequestBody @Valid ApprovalDTO approvalDTO,
            @RequestParam Long approverId,
            @RequestParam String approverName) {
        boolean result = approvalService.approveDocument(approvalDTO, approverId, approverName);
        return Result.success(result);
    }

    /**
     * 获取公文审批记录
     */
    @GetMapping("/document/{documentId}")
    public Result<List<ApprovalRecord>> getApprovalRecords(@PathVariable Long documentId) {
        List<ApprovalRecord> records = approvalService.getApprovalRecords(documentId);
        return Result.success(records);
    }

    /**
     * 获取我的审批记录
     */
    @GetMapping("/my")
    public Result<IPage<ApprovalRecord>> getMyApprovalRecords(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "20") Integer size,
            @RequestParam Long userId) {
        IPage<ApprovalRecord> records = approvalService.getMyApprovalRecords(page, size, userId);
        return Result.success(records);
    }
} 